<?php

ini_set("display_errors", "On");
error_reporting(E_ALL);

// 引入数据库连接文件
require_once 'coon/connection.php';

$username = $_POST['username'];
$pwd =  password_hash($_POST['pwd'], PASSWORD_DEFAULT);
// $addStuPwd = password_hash("123456", PASSWORD_DEFAULT);

// 查询语句
$querySql = "select id from user where username='$username'";
// 连接数据库，并查询
$result = mysqli_query($GLOBALS['conn'], $querySql);

//echo $result_config;
if (mysqli_num_rows($result) > 0) {
	echo "
<script>
    alert('该用户名已存在，请重新输入！');
    history.go(-1);
</script>";
} else {
	// 获取当前时间
	$now = date('Y-m-d H:i:s', time());
	$addSql = "INSERT INTO user(create_time, update_time, is_delete, username, pwd)VALUES ('$now','$now',0,'$username','$pwd')";
	if (mysqli_query($GLOBALS['conn'], $addSql)) {
		echo "
            <script>
                alert('注册成功！');
                window.location.href=document.referrer;
            </script>
        ";
	} else {
		echo "
            <script>
                alert('注册失败！');
                history.back();
            </script>
        ";
	}
	
}

